﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using System.Reflection;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Web.Caching;
using NickLee.Common;
using GPCSC.Web;

namespace GPCSC.Web
{
    public class PageBase : System.Web.UI.Page
    {
        #region Method:属性

        #region 通用属性
        /// <summary>
        /// 私有变量_UISet
        /// </summary>
        protected DataSet o_uiDataSet = new DataSet();
        /// <summary>
        /// 界面层数据集
        /// </summary>
        protected DataSet m_uiDataSet
        {
            get
            {
                // TODO:  添加 o_uiDataSet 实现
                return o_uiDataSet;
            }
            set
            {
                // TODO:  添加 o_uiDataSet 实现
                o_uiDataSet = value;
            }
        }

        protected DataTable o_uiDataTable = new DataTable();
        /// <summary>
        /// 界面层数据表
        /// </summary>
        protected DataTable m_uiDataTable
        {
            get
            {
                // TODO:  添加 BaseRule.OperationCode getter 实现
                return o_uiDataTable;
            }
            set
            {
                // TODO:  添加 BaseRule.OperationCode setter 实现
                o_uiDataTable = value;
            }
        }

        private string o_pageTitle = string.Empty;
        /// <summary>
        /// 页面标题
        /// </summary>
        protected string m_pageTitle
        {
            get
            {
                // TODO:  添加 BaseRule.OperationCode getter 实现
                return o_pageTitle;
            }
            set
            {
                // TODO:  添加 BaseRule.OperationCode setter 实现
                o_pageTitle = value;
            }
        }

        protected string o_baseSelect = string.Empty;
        /// <summary>
        /// 查询字段
        /// </summary>
        protected string m_baseSelect
        {
            get
            {
                // TODO:  添加 BaseRule.OperationCode getter 实现
                return o_baseSelect;
            }
            set
            {
                // TODO:  添加 BaseRule.OperationCode setter 实现
                o_baseSelect = value;
            }
        }

        /// <summary>
        /// 记录总数.变量.1000w、10000w数据集使用
        /// </summary>
        protected int o_recordCount;
        /// <summary>
        /// 记录总数.属性.1000w、10000w数据集使用
        /// </summary>
        protected int m_recordCount
        {
            get
            {
                return o_recordCount;
            }
        }

        /// <summary>
        /// 日志表头
        /// </summary>
        //public string o_logTitle
        //{
        //    get
        //    {
        //        string logTitle = "";
        //        try
        //        {
        //            if (Session[c_obj.s_baseTable] != null)
        //            {
        //                Hashtable tTable = (Hashtable)Session[c_obj.s_baseTable];
        //                byte[] userinfo = (byte[])tTable[c_obj.s_userInfo];
        //                Hashtable dTable = NewDomain.Common.CompressData.UnCompressHashtable(userinfo);
        //                tb_user user = (tb_user)dTable["tb_user"];
        //                logTitle = "用户编号:" + user.ID.ToString() + "," + user.USERNAME + "用户:";

        //            }
        //        }
        //        catch (System.Exception ee)
        //        {
        //        }
        //        return logTitle;


        //    }
        //}


        #endregion
         

        #endregion

        #region Object:对象

        /// <summary>
        /// 基类哈希表,在整个系统中存在
        /// 用于保存系统登陆时候的Session
        /// 在整个UI层Session名称为Session["o_baseTable"]
        /// </summary>
        protected Hashtable o_baseTable = new Hashtable();


        /// <summary>
        /// 界面哈希表,在当前页面存在
        /// 用于保存由UIFactory函数返回的获取的控件和控件值的Hashtable
        /// </summary>
        protected Hashtable o_uiTable = new Hashtable();

        /// <summary>
        /// 业务层Hashtable,可以和o_uiTable一起传入业务层处理
        /// 用于UI层和业务层的数据传递
        /// </summary>
        protected Hashtable o_controllTable = new Hashtable();

        /// <summary>
        /// 出错提示,默认值""
        /// </summary>
        //		protected string PageErrorMessage = "";
        protected string o_errMsg = string.Empty;

        protected string depsession = "";

        /// <summary>
        /// 出错状态,默认值false
        /// </summary>
        //		protected bool PageErrorState = false;
        protected bool o_errState = false;

        /// <summary>
        /// 标识base.o_baseTable是否需要重新更新Session
        /// true:更新,false:不更新
        /// </summary>
        protected bool o_baseTableUpdateState = false;
       

        #endregion

        #region Function:函数

        #region 公共函数

        /// <summary>
        /// 基类页面载入函数
        /// 对AJAX模式不起效果(.net Framework 2.0中 Microsoft Asp.net ajax可以使用
        /// 其他ajax都调用不到
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void f_pageBase_Load(object sender, EventArgs e)
        {
            //页面自动维护滚动条位置
            //this.MaintainScrollPositionOnPostBack = true;
            //整个流程需要的控制部分
            var obj = Session[c_obj.s_baseTable];
            if (obj != null)
            {
                //从Session中获取哈希对象列表
                this.o_baseTable = (Hashtable)obj;
            }
        }


        //public string WorkFlow_Day(string POSTID, string active)
        //{
        //    DataSet days = new BLL.Flow_PostDay().GetList("PostID='" + POSTID + "' and ActivityCh='" + active + "' ");
        //    if (days.Tables[0].Rows.Count > 0)
        //    {
        //        return days.Tables[0].Rows[0]["Days"].ToString();
        //    }
        //    else
        //    {
        //        return "0";
        //    }
        //}
        /// <summary>
        /// 已重载.计算两个日期的时间间隔,返回的是时间间隔的日期差的绝对值.
        /// </summary>
        /// <param name="DateTime1">第一个日期和时间</param>
        /// <param name="DateTime2">第二个日期和时间</param>
        /// <returns></returns>
        public int DateDiffs(DateTime DateTime1, DateTime DateTime2)
        {
            int dateDiff = 0;
            try
            {
                TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
                TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
                TimeSpan ts = ts1.Subtract(ts2).Duration();
                dateDiff = ts.Days;
            }
            catch
            {

            }
            return dateDiff;
        }

 


       

        #endregion
        /// <summary>
        /// 返回 ViewState指定名称的值
        /// </summary>
        /// <param name="viewstateName">指定的名称</param>
        /// <returns>返回值对象 object对象</returns>
        protected object f_viewstateToObj(string viewstateName)
        {
            if (ViewState[viewstateName] == null)
            {
                return null;
            }
            else if (ViewState[viewstateName].ToString() == "")
            {
                return "";
            }
            return ViewState[viewstateName];
        }

        /// <summary>
        /// 返回 ViewState指定名称的值
        /// </summary>
        /// <param name="viewstateName">指定的名称</param>
        /// <returns>返回值对象 string对象</returns>
        protected object f_viewstateToString(string viewstateName)
        {
            if (ViewState[viewstateName] == null)
            {
                return "";
            }
            else if (ViewState[viewstateName].ToString() == "")
            {
                return "";
            }
            return ViewState[viewstateName].ToString().Trim();
        }

        /// <summary>
        /// 返回 ViewState指定名称的值
        /// </summary>
        /// <param name="viewstateName">指定的名称</param>
        /// <returns>返回值对象 string大写对象</returns>
        protected object f_viewstateToUpperString(string viewstateName)
        {
            if (ViewState[viewstateName] == null)
            {
                return "";
            }
            else if (ViewState[viewstateName].ToString() == "")
            {
                return "";
            }
            return ViewState[viewstateName].ToString().Trim().ToUpper();
        }

        #region 构造函数
        /// <summary>
        /// 基础页面构造函数,做为为基类增加PageBase_Load事件
        /// 处理Session等公共信息
        /// </summary>
        public PageBase()
        {
            this.Load += new EventHandler(f_pageBase_Load);
        }
        #endregion



        #endregion



        #region Object Emun Class:对象枚举

        /// <summary>
        /// 单个Class字符串枚举
        /// 命名空间gwmWebApp.PageBase
        /// </summary>
        protected class c_obj
        {
            #region Session string(s_ means Session)

            /// <summary>
            /// 保存对象:基础Session哈希表;
            /// object 类型,命名空间Fortune
            /// 新构架保存基础缓存
            /// </summary>
            public static string s_baseTable
            {
                get
                {
                    return _s_baseTable;
                }
            }
            private static string _s_baseTable = "baseTable";

            public static string BaseList
            {
                get
                {
                    return "BaseList";
                }
            }


            /// <summary>
            /// 修改处理时，页面缓存名称
            /// </summary>
            public static string s_EditPageState
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return _s_EditPageState;
                }
            }
            private static string _s_EditPageState = "editPageState";

            /// <summary>
            /// DataBase.config字符串是否解密
            /// </summary>
            public static string s_configDecryptState
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return _s_configDecryptState;
                }
            }
            private static string _s_configDecryptState = "false";

            /// <summary>
            /// 第一次载入的时候根据菜单点击产生Session
            /// </summary>
            public static string s_ajaxListLoad
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return _s_ajaxListLoad;
                }
            }
            private static string _s_ajaxListLoad = "ajaxListLoad";

            /// <summary>
            /// 保存对象:所有用户登录信息;
            /// object 类型,命名空间Fortune
            /// 新构架保存基础缓存
            /// </summary>
            public static string s_userInfo
            {
                get
                {
                    return _s_userInfo;
                }
            }
            private static string _s_userInfo = "userInfo";

            /// <summary>
            /// 点击菜单后,保存MENUID进入QueryString,并在LIST页面和编辑页面控制权限
            /// </summary>
            public static string s_menuID
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return _s_menuID;
                }
            }
            private static string _s_menuID = "MENUID";

            private static string _start = string.Empty;
            public static string o_start
            {
                get
                {
                    return _start;
                }
                set
                {
                    _start = value;
                }
            }

            /// <summary>

            /// </summary>
            private static Guid _GuidTable = Guid.Empty;
            public static Guid o_GuidTable
            {
                get
                {
                    return _GuidTable;
                }
                set
                {
                    _GuidTable = value;
                }
            }
            #endregion

           
           

            #region Querystring(q_ means QueryString)
            /// <summary>
            /// 设施类别号
            /// </summary>
            public static string q_fno
            {
                get
                {
                    return _fno;
                }
            }
            private static string _fno = "FNO";

            #endregion

            #region  Page string(b_:All page use,be_:Edit page use,bl_:List page use)

            #region BasePage

            /// <summary>
            /// Fortune(ALL.OneTable).cst生成时需要状态
            /// </summary>
            public static string b_ajaxmodel
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return _b_ajaxmodel;
                }
            }
            private static string _b_ajaxmodel = "ajaxmodel";

            /// <summary>
            /// 页面参数名称
            /// </summary>
            public static string p_command
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return o_command;
                }
            }
            private static string o_command = "Command";


            /// <summary>
            /// 页面参数名称
            /// </summary>
            //public static string p_id
            //{
            //    get
            //    {
            //        // TODO:  添加 BaseRule.OperationCode getter 实现
            //        return o_id;
            //    }
            //}
            //private static string o_id = "id";


            /// <summary>
            /// 页面参数
            /// </summary>
            public static string p_commandArg
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return o_commandArg;
                }
            }
            private static string o_commandArg = "CommandArg";

            /// <summary>
            /// 界面状态
            /// </summary>
            public static string p_uiStatic
            {
                get
                {
                    // TODO:  添加 BaseRule.OperationCode getter 实现
                    return o_uiStatic;
                }

            }
            private static string o_uiStatic = "uiStatic";

            /// <summary>
            /// errMsg:页面错误信息提示字段名称
            /// </summary>
            public static string p_errMsg
            {
                get
                {
                    return o_errMsg;
                }
            }
            private static string o_errMsg = "errMsg";


           

            #endregion

            #region EditPage
            /// <summary>
            /// 新增
            /// </summary>
            public static string p_new
            {
                get
                {
                    return o_new;
                }
            }
            private static string o_new = "NEW";

            /// <summary>
            /// 修改
            /// </summary>
            public static string p_edit
            {
                get
                {
                    return o_edit;
                }
            }
            private static string o_edit = "EDIT";

            /// <summary>
            /// 查看
            /// </summary>
            public static string p_view
            {
                get
                {
                    return o_view;
                }
            }
            private static string o_view = "VIEW";

            /// <summary>
            /// 传递的菜单值
            /// </summary>
            public static string p_menuid
            {
                get
                {
                    return o_menuid;
                }
            }
            private static string o_menuid = "MENUID";
            #endregion

            #endregion
           
           
        };

        /// <summary>
        /// 下拉菜单对象
        /// </summary>
        public class DropDownListClass
        {
            private string _Name = string.Empty;
            public string Name
            {
                get
                {
                    return _Name;
                }
                set
                {
                    _Name = value;
                }
            }


            private string _Value = string.Empty;
            public string Value
            {
                get
                {
                    return _Value;
                }
                set
                {
                    _Value = value;
                }
            }

        };



        #endregion

       
    }

    /// <summary>
    /// 有权限和Session缓存控制的aspx页面继承基类
    /// </summary>
    public class Pages : PageBase
    {
        public Pages()
        {
            this.Load += new EventHandler(f_pagesLoad);
        }

        private void f_pagesLoad(object sender, EventArgs e)
        {
            if (Session[c_obj.s_baseTable] == null)
            {
                //JSUtil.Alert(this, "用户登陆缓存失效,请重新登陆！");
                JSUtil.f_ajaxExecuteStartup(this, "alert('用户登陆缓存失效,请重新登陆！');top.location.href='../logout.aspx?logtype=logout';");
                //JSUtil.ExecuteStartup(this, "alert('用户登陆缓存失效,请重新登陆！');");
                return;
            }
        }

        //public void f_SecurityConfigMeun(NickLee.Web.UI.Menu meun,string meunid)
        //{
        //    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
        //    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
        //    Model.CL_VALUEMENU_S[] user = (Model.CL_VALUEMENU_S[])userInfoTable["SYS_UserValue"];
        //    foreach (Model.CL_VALUEMENU_S value in user)
        //    {
        //        if (value.CL_MENUID_PK.ToString() == meunid)
        //        {
        //            meun.FindItemById(value.ControlNAME).Visible = true;
        //        }
        //    }
        //}

      
    }
 
}
